package com.jeeplus.modules.api.web;

import com.jeeplus.common.beanvalidator.BeanValidators;
import com.jeeplus.common.json.ReturnJson;
import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.api.service.ApiService;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.mapper.DataRuleMapper;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.tools.utils.MultiDBUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Administrator
 * @title: ApiController
 * @projectName JeePlus
 * @description: TODO
 * @date 2019/11/216:41
 */
@Api(value = "ApiController", description = "API控制器")
@Controller
@RequestMapping(value = "${apiPath}")
@CrossOrigin
public class ApiController extends BaseController {
    @Autowired
    private  DataRuleMapper dataRuleMapper = SpringContextHolder.getBean(DataRuleMapper.class);
    private ApiService apiService = SpringContextHolder.getBean(ApiService.class);
    @ApiOperation(notes = "test", tags = {"test", "test"}, httpMethod = "GET", value = "测试")
    @ApiImplicitParams({@ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "query", dataType = "string")})
    @RequestMapping(value = "apitest")
    @ResponseBody
    public ReturnJson getTest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ReturnJson ajaxJson = new ReturnJson();
        ajaxJson.setCode(200);
        ajaxJson.setData(apiService.test());

        return ajaxJson;
    }
    @NotNull(message="不能为空")
    private String no="";
    //region 视图功能
    @RequestMapping(value = "index")
    public String index(){
        return "modules/Api/index";
    }
    @RequestMapping(value = "form")
    public String form(){
        return "modules/Api/form";
    }
    @RequestMapping(value = "treeData")
    @ResponseBody
    public ReturnJson treeData(User user){
        ReturnJson returnJson=new ReturnJson();

        System.out.println(beanValidatorList(no));
        return returnJson;
    }
    //endregion
    //region 获取数据

    //endregion
}
